package org.dromara.timemate.controller;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.utils.ValidatorUtils;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.timemate.domain.bo.WearerUserBo;
import org.dromara.timemate.domain.vo.WearerUserVo;
import org.dromara.timemate.service.WearerUserService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import lombok.RequiredArgsConstructor;

import java.util.Arrays;

/**
 * 穿戴者信息 Controller
 */

@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/tm/weareruser")
public class WearerUserController extends BaseController {

    private final WearerUserService weareruserService;


    /**
     * 穿戴用户列表
     *
     * @param pageQuery 分页对象
     * @return {@link TableDataInfo}
     */
    @GetMapping("/listWearerUser")
    public TableDataInfo<WearerUserVo> listWearerUser(PageQuery pageQuery) {
        return weareruserService.queryPageWearerUserList(pageQuery);
    }

    /**
     * 添加穿戴用户信息
     * @param wearerUserBo：wearerName, wearerPhonenumber
     * @return
     */
    @PostMapping("/add")
    public R<Void> addWearerUser(@Valid @RequestBody WearerUserBo wearerUserBo){
        ValidatorUtils.validate(wearerUserBo, AddGroup.class);
        return toAjax(weareruserService.addWearerUser(wearerUserBo));
    }

    /**
     * 通过上传用户id，删除穿戴用户信息
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public R<Void> deleteWearerUserByIds(@NotEmpty(message = "主键不能为空")
                                         @PathVariable Long[] id) {
        return toAjax(weareruserService.deleteWearerUserByIds(Arrays.asList(id)));
    }


}
